package me.pplay.playtalk.activity.setting;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import me.pplay.playtalk.ApplicationTrans;
import me.pplay.playtalk.R;
import me.pplay.playtalk.activity.BaseActivity;
import me.pplay.playtalk.adapter.CommonAdapter;
import me.pplay.playtalk.bean.CommonControlID;
import me.pplay.playtalk.callback.CommonAdapterOnClickCallBack;
import me.pplay.playtalk.protocol.TpChat;
import me.pplay.playtalk.protocol.bean.TPBuddyinfo;
import me.pplay.playtalk.util.BuddyInfoUtil;
import me.pplay.playtalk.util.LogManager;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

public class IgnoreFriendsActivity extends BaseActivity {
	private List<Map<String, Object>> mData;
	private ListView list;
	private LinkedList<TPBuddyinfo> ignorelist;
	private TpChat tpChat;
	private List<Map<String, Object>> listData = new ArrayList<Map<String, Object>>();
	private ProgressDialog progressDialog;
	private CommonAdapter adapter;
	Handler handler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			// TODO Auto-generated method stub
			super.handleMessage(msg);
			switch (msg.what) {
			default:
				break;
			}
		}
	};
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.layout_ignorefriends);
		mData = getData();

		CommonControlID holderId = new CommonControlID();
		holderId.itemLayout = R.layout.layout_ignorefriendslist;
		holderId.leftImgId = R.id.ignorefriends_img;
		holderId.rightImgId = R.id.ignorefriends_chat;
		holderId.leftStrId = R.id.ignorefriends_title;
		holderId.leftStr1Id = R.id.ignorefriends_topic;
		adapter = new CommonAdapter(IgnoreFriendsActivity.this, mData, holderId, new CommonAdapterOnClickCallBack() {

			@Override
			public void OnClickCallback(int pos, int ViewId, View v) {
				// TODO Auto-generated method stub
				LogManager.LogShow("IgnoreFriendsActivity", "OnClickCallback position " + pos);

			}
		});
		list = (ListView) this.findViewById(R.id.ignorefriends_list); // 联系人ListView
		list.setAdapter(adapter);// 将数据适配器与Activity进行绑定
		ApplicationTrans appState = (ApplicationTrans) getApplicationContext();
		tpChat = appState.getTpChat();

		clickEvents();
	}
	private List<Map<String, Object>> getData() {
		listData.clear();
		ApplicationTrans appState = (ApplicationTrans) getApplicationContext();
		TpChat tpChat = appState.getTpChat();
		ignorelist = tpChat.tp_chat_ignorelist();
		if (ignorelist != null) {
			for (TPBuddyinfo g : ignorelist) {
				LogManager.LogShow("IgnoreFriendsActivity", "getName() " + BuddyInfoUtil.getAlias(g));
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("leftStr", BuddyInfoUtil.getAlias(g));
				map.put("leftStr1", g.getSignature());
				//BuddyInfoUtil
				map.put("leftImg", R.drawable.community_default);
				map.put("rightImg", R.drawable.commnutiy_chat);
				listData.add(map);

			}
		}
		return listData;
	}

	private void clickEvents() {
		list.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
				LogManager.LogShow("IgnoreFriendsActivity", "onItemClick alias:");
				progressDialog = ProgressDialog.show(IgnoreFriendsActivity.this, getString(R.string.loading), getString(R.string.waittng), true, false); 
				progressDialog.show();
			}
		});

	}
}
